package site.marqstree.latte.ec.detail;

/*
 * 项目名: EleCommerce
 * 包名: site.marqstree.latte.ec.detail
 * 文件名: RecyclerImageAdapter
 * 创建者: marqstree
 * 创建时间: 2020/2/10 16:12
 * 描述: TODO
 */

import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

import site.marqstree.latte.ec.R;
import site.marqstree.latte.ui.recycler.ItemType;
import site.marqstree.latte.ui.recycler.MultipleFields;
import site.marqstree.latte.ui.recycler.MultipleItemEntity;
import site.marqstree.latte.ui.recycler.MultipleRecyclerAdapter;

public class RecyclerImageAdapter extends MultipleRecyclerAdapter {

    private static final RequestOptions OPTIONS = new RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .dontAnimate();

    protected RecyclerImageAdapter(List<MultipleItemEntity> data) {
        super(data);
        addItemType(ItemType.SINGLE_BIG_IMAGE, R.layout.item_image);
    }

    @Override
    protected void convert(BaseViewHolder holder, MultipleItemEntity entity) {
        super.convert(holder, entity);
        final int type = holder.getItemViewType();
        switch (type) {
            case ItemType.SINGLE_BIG_IMAGE:
                final ImageView imageView = holder.getView(R.id.image_rv_item);
                final String url = entity.getField(MultipleFields.IMAGE_URL);
                Glide.with(getContext())
                        .load(url)
                        .into(imageView);
                break;
            default:
                break;
        }
    }
}
